home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Frameworks / DropShell Pascal / DropShell.p < prev    next >
Encoding:
Text File  |  1994-05-27  |  6.5 KB  |  261 lines  |  [TEXT/MPS ]

  1. {******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.p
  5. **
  6. **   Description:    Main application code for the DropShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **
  16. *******************************************************************************
  17. **                      R E V I S I O N   H I S T O R Y
  18. *******************************************************************************
  19. **
  20. **      Date        Time    Author    Description
  21. **    --------    -----    ------    ---------------------------------------------
  22. **    01/25/92            LDR        Added $I- for Think Pascal double-init problems
  23. **                                Added Otherwise clauses to all CASE statements 
  24. **                                    ThP Runtime needs them, for some reason?!?
  25. **    12/09/91            LDR        Added support for new "Select File…" menu item
  26. **                                Quit now sends AEVT to self to be politically correct
  27. **                                Added support for the new gSplashScreen
  28. **    11/24/91            LDR        Added support for the Apple Menu (duh!)
  29. **                                Moved CenterAlert & ErrorAlert to DSUtils
  30. **    10/30/91            LDR        Modified USES clause for new include & ifc'ed ThP
  31. **    10/28/91            LDR        Officially renamed DropShell (from QuickShell)
  32. **                                Added a bunch of comments for clarification
  33. **    04/09/91    00:02    LDR        Original Version
  34. **
  35. ******************************************************************************}
  36.  
  37. PROGRAM DropShell;
  38.  
  39. {$IFC THINK_Pascal}
  40.     USES
  41.         Script, DSGlobals, DSUtils, DSUserProcs, DSAppleEvents;    {just the DropShell files}
  42. {$ELSEC}
  43.     USES
  44.     { First load standard interface files}
  45.         MemTypes, QuickDraw, 
  46.  
  47.     { Now include the stuff from OSIntf }
  48.         OSIntf, 
  49.  
  50.     { Now Include the stuff from ToolIntf.p }
  51.         ToolIntf, Packages, GestaltEqu, 
  52.  
  53.     { Then any OTHER Toolbox interfaces... }
  54.         Files, Aliases, AppleEvents,
  55.  
  56.     { And finally any files from DropShell }
  57.         DSGlobals, DSUtils, DSUserProcs, DSAppleEvents;
  58. {$ENDC THINK_Pascal}
  59.  
  60. {CODE BEGINS HERE}
  61.  
  62. {$IFC THINK_Pascal}
  63. {$ELSEC}
  64.     {
  65.         This routine is automatically linked in by the MPW Linker. 
  66.         This external reference to it is done so that we can unload its segment, %A5Init.
  67.     }
  68.     PROCEDURE _DataInit; EXTERNAL;
  69. {$ENDC THINK_Pascal}
  70.  
  71.     {Simple routine installed by InitDialogs for the Resume button in Bomb boxes}
  72.     PROCEDURE Panic;
  73.     BEGIN
  74.         ExitToShell;
  75.     END;
  76.  
  77.     {$S Initialize}
  78.     {Nothing special here, just initting the toolbox}
  79.     PROCEDURE InitToolbox;
  80.     BEGIN
  81. {$IFC THINK_Pascal}
  82. {$I-}
  83. {$ELSEIF }
  84.     UnloadSeg(@_DataInit);    {we love you MPW!}
  85. {$ENDC THINK_Pascal}
  86.  
  87.         InitGraf(@qd.thePort);
  88.         InitFonts;
  89.         InitWindows;
  90.         InitMenus;
  91.         TEInit;
  92.         InitDialogs(@Panic);
  93.  
  94.         InitCursor;
  95.         FlushEvents(everyEvent, 0);
  96.         
  97.         {how about some memory fun!}
  98.         MoreMasters;
  99.         MoreMasters;    {two should be enough!}
  100.     END;
  101.     
  102.     {
  103.         Let's setup those global variables that the DropShell uses.
  104.         
  105.         If you add any globals for your own use,
  106.         init them in the InitUserGlobals routine in DSUserProcs.c
  107.     }
  108.     FUNCTION InitGlobals: Boolean;
  109.     VAR
  110.         aLong: longint;
  111.     BEGIN
  112.         gDone := FALSE;
  113.         gOApped := FALSE;    {Assume it wasn't, since most users wont!}
  114.         gHasAppleEvents := (Gestalt(gestaltAppleEventsAttr, aLong) = noErr);
  115.         gSplashScreen := NIL;
  116.         
  117.         InitGlobals := InitUserGlobals;    {call the user proc}
  118.     END;
  119.     
  120.     {
  121.         Again, nothing fancy.  Just setting up the menus.
  122.         
  123.         If you add any menus to your DropBox - insert them here!
  124.     }
  125.     PROCEDURE SetUpMenus;
  126.     BEGIN
  127.         gAppleMenu := GetMenu(kAppleNum);
  128.         AddResMenu(gAppleMenu, 'DRVR');
  129.         InsertMenu(gAppleMenu, 0);
  130.  
  131.         gFileMenu := GetMenu(kFileNum);
  132.         InsertMenu(gFileMenu, 0);
  133.         DrawMenuBar;
  134.     END;
  135.     
  136.     {
  137.         This routine is called during startup to display a splash screen.
  138.         
  139.         This was recommend by the Blue Team HI person, John Sullivan, who
  140.         feels that all apps should display something so that users can easily
  141.         tell what is running, and be able to switch by clicking.  Thanks John!
  142.     }
  143.     PROCEDURE InstallSplashScreen;
  144.     CONST
  145.         windowPicID = 128;
  146.     VAR
  147.         picH: PicHandle;
  148.     BEGIN
  149.         IF (gSplashScreen = NIL) THEN { show the splash screen window }
  150.         BEGIN
  151.             picH := GetPicture(windowPicID);
  152.             IF picH <> NIL THEN
  153.             BEGIN
  154.                 gSplashScreen := GetNewWindow(windowPicID, NIL, Pointer(-1));
  155.                 IF gSplashScreen <> NIL THEN
  156.                 BEGIN
  157.                     SetWindowPic(gSplashScreen, picH);
  158.                     { Don't show it here, let it happen during an 'oapp' }
  159.                     { ShowWindow(gSplashScreen); }
  160.                 END;
  161.             END;
  162.         END;
  163.     END;
  164.  
  165. {$S Main}
  166.  
  167. {** Standard Event Handling routines **}
  168.     PROCEDURE ShowAbout;
  169.     VAR
  170.         itemHit: integer;
  171.     BEGIN
  172.         itemHit := Alert(128, NIL);
  173.     END;
  174.     
  175.     PROCEDURE DoMenu(retVal: longint);
  176.     VAR
  177.         menuID, itemID: integer;
  178.         itemStr: Str255;
  179.         refNum: integer;
  180.     BEGIN
  181.         menuID := HiWord(retVal);
  182.         itemID := LoWord(retVal);
  183.         
  184.         CASE menuID OF
  185.             kAppleNum:
  186.                 IF itemID = 1 THEN    {handle the about box}
  187.                     ShowAbout    
  188.                 ELSE                {get the DA's}
  189.                 BEGIN
  190.                     GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  191.                     refNum := OpenDeskAcc(itemStr);
  192.                 END;
  193.             kFileNum:
  194.                 IF itemID = 1 THEN    {Select File…}
  195.                     SelectFile
  196.                 ELSE
  197.                     SendQuitToSelf;    {send me a quit event}
  198.             OTHERWISE
  199.                 {do nothing}
  200.         END;
  201.         HiliteMenu(0);        {turn it off}
  202.     END;
  203.     
  204.     PROCEDURE DoMouseDown(curEvent:EventRecord);
  205.     VAR
  206.         whichWindow:    WindowPtr;
  207.         whichPart:        integer;
  208.     BEGIN
  209.         whichPart := FindWindow (curEvent.where, whichWindow);
  210.         case whichPart of
  211.             inMenuBar:        DoMenu (MenuSelect (curEvent.where));
  212.             inSysWindow:    SystemClick (curEvent, whichWindow);
  213.             inDrag:            DragWindow(whichWindow, curEvent.where, qd.screenBits.bounds);
  214.             inDesk, inContent, inGrow, inGoAway, inZoomIn, inZoomOut:
  215.                     {Do nothing};
  216.             OTHERWISE
  217.                     {Do nothing here either}
  218.         end; {case}
  219.     END; {DoMouseDown}
  220.     
  221.     PROCEDURE DoKeyDown(curEvent:EventRecord);
  222.     VAR
  223.         ch:                char;
  224.     BEGIN
  225.         ch := CHR(BitAnd (curEvent.message, charCodeMask));
  226.         
  227.         IF BitAnd (curEvent.modifiers, cmdKey) <> 0 THEN
  228.             DoMenu (MenuKey (ch));
  229.     END; {DoKeyDown}
  230.  
  231. {Main Program Starts Here}
  232. BEGIN
  233.     InitToolbox;
  234.     IF (InitGlobals) THEN
  235.     BEGIN
  236.         IF gHasAppleEvents THEN
  237.         BEGIN
  238.             InitAEVTStuff;
  239.             SetupMenus;
  240.             InstallSplashScreen;
  241.             
  242.             WHILE NOT gDone DO
  243.             BEGIN
  244.                 gWasEvent := WaitNextEvent(everyEvent, gEvent, 0, NIL);
  245.                 IF gWasEvent THEN
  246.                 BEGIN
  247.                     CASE gEvent.what OF
  248.                         kHighLevelEvent:    DoHighLevelEvent(gEvent);
  249.                         mouseDown:            DoMouseDown(gEvent);
  250.                         keyDown, autoKey:    DoKeyDown(gEvent);
  251.                         OTHERWISE
  252.                                 {Do nothing}
  253.                     END; {case}
  254.                 END;
  255.             END;    
  256.         END
  257.         ELSE
  258.             ErrorAlert(kErrStringID, kCantRunErr, 0);
  259.     END;
  260. END.
  261.